home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWODMisc / FWSUUtil.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  4.0 KB  |  141 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWSUUtil.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWSUUTIL_H
  13. #include "FWSUUtil.h"
  14. #endif
  15.  
  16. #ifndef FWACQUIR_H
  17. #include "FWAcquir.h"
  18. #endif
  19.  
  20. #ifndef FWPOINT_H
  21. #include "FWPoint.h"
  22. #endif
  23.  
  24. #ifndef FWRECT_H
  25. #include "FWRect.h"
  26. #endif
  27.  
  28. #ifndef FWBARRAY_H
  29. #include "FWBArray.h"
  30. #endif
  31.  
  32. #ifndef SOM_ODStorageUnit_xh
  33. #include <StorageU.xh>
  34. #endif
  35.  
  36. #ifndef SOM_ODStorageUnit_xh
  37. #include <StorageU.xh>
  38. #endif
  39.  
  40. #ifndef SOM_Module_OpenDoc_Errors_defined
  41. #include <ErrorDef.xh>
  42. #endif
  43.  
  44. #ifndef SOM_ODTranslation_xh
  45. #include <Translt.xh>
  46. #endif
  47.  
  48. #ifndef SOM_ODSession_xh
  49. #include <ODSessn.xh>
  50. #endif
  51.  
  52. //========================================================================================
  53. // Runtime Informations
  54. //========================================================================================
  55.  
  56. #ifdef FW_BUILD_MAC
  57. #pragma segment fwodmisc
  58. #endif
  59.  
  60. //========================================================================================
  61. //    Storage Unit Utilities
  62. //========================================================================================
  63.  
  64. //----------------------------------------------------------------------------------------
  65. // FW_SUAddPropValue
  66. //----------------------------------------------------------------------------------------
  67.  
  68. void FW_SUAddPropValue(Environment* ev, ODStorageUnit* su, ODPropertyName prop, ODValueType val)
  69. {
  70.     if (!su->Exists(ev, prop, NULL, 0))
  71.     {
  72.         su->AddProperty(ev, prop)->AddValue(ev, val);
  73.     }
  74.     else
  75.     {
  76.         su->Focus(ev, prop, kODPosUndefined, NULL, 0, kODPosUndefined);
  77.         if (!su->Exists(ev, prop, val, 0))
  78.             su->AddValue(ev, val);
  79.     }
  80. }
  81.  
  82. //----------------------------------------------------------------------------------------
  83. // FW_SURemoveValue
  84. //----------------------------------------------------------------------------------------
  85.  
  86. void FW_SURemoveValue(Environment* ev, ODStorageUnit* su,  ODPropertyName prop, ODValueType val)
  87. {
  88.     if (su->Exists(ev, prop, val, 0))
  89.     {
  90.         su->Focus(ev, prop, kODPosUndefined, val, 0, kODPosUndefined);
  91.         su->Remove(ev);
  92.     }
  93. }
  94.  
  95. //---------------------------------------------------------------------------------------
  96. //    FW_SUClearValue
  97. //---------------------------------------------------------------------------------------
  98.  
  99. void FW_SUClearValue(Environment* ev, ODStorageUnit* storageUnit, ODPropertyName prop, ODValueType val)
  100. {
  101.     storageUnit->Focus(ev, prop, kODPosUndefined, val, 0, kODPosUndefined); // the offset if zero after focus
  102.     unsigned long size = storageUnit->GetSize(ev);
  103.     if (size != 0)
  104.         storageUnit->DeleteValue(ev, size);
  105. }
  106.  
  107. //---------------------------------------------------------------------------------------
  108. //    FW_SUDeleteEndOfFocusedValue
  109. //---------------------------------------------------------------------------------------
  110. // Assume focus on a property/value
  111.  
  112. void FW_SUDeleteEndOfFocusedValue(Environment* ev, ODStorageUnit* storageUnit)
  113. {
  114.     unsigned long toDelete = storageUnit->GetSize(ev) - storageUnit->GetOffset(ev);
  115.     if (toDelete > 0)
  116.         storageUnit->DeleteValue(ev, toDelete);
  117. }
  118.  
  119. #ifdef FW_BUILD_MAC
  120. //----------------------------------------------------------------------------------------
  121. //    FW_MacSUReadHFSFlavor
  122. //----------------------------------------------------------------------------------------
  123.  
  124. FW_Boolean FW_MacSUReadHFSFlavor(Environment* ev, ODStorageUnit* su, ODPropertyName prop, HFSFlavor& flavor)
  125. {
  126.     ODTranslation *translate = su->GetSession(ev)->GetTranslation(ev);
  127.     ODType applehfs = translate->GetISOTypeFromPlatformType(ev, 0x68667320UL, kODPlatformDataType); // 'hfs '
  128.     
  129.     if (FW_SUExistsThenFocus(ev, su, prop, applehfs))
  130.     {    
  131.         FW_CByteArray byteArray;    
  132.         su->GetValue(ev, sizeof(HFSFlavor), byteArray);
  133.         byteArray.CopyBuffer(&flavor, sizeof(HFSFlavor));
  134.         return true;
  135.     }
  136.     
  137.     return false;
  138. }
  139. #endif
  140.  
  141.